cmake_minimum_required(VERSION 3.0)
if(POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif()
if(POLICY CMP0063)
  cmake_policy(SET CMP0063 NEW)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../lib/functions.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../lib/options.cmake)

j_set_path(j_project_file ${PROJECT_FILE})
set(j_config ${CMAKE_BUILD_TYPE})
include(${j_project_file})		# second pass
j_assert("function j_prepare not defined" COMMAND j_prepare)
j_assert("function j_main not defined" COMMAND j_main)

j_define_global_variables()
include(${CMAKE_CURRENT_LIST_DIR}/../../config.cmake OPTIONAL)
j_prepare()
project(${j_project_name})
j_set_global_variables()

include(${CMAKE_CURRENT_LIST_DIR}/../lib/config.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../lib/init.cmake)
j_set_global_variables()
j_main()

if (COMMAND j_pre_sync_external_projects)
	j_pre_sync_external_projects()
endif()
#sync dependency project
j_sync_external_projects()
if (COMMAND j_post_sync_external_projects)
	j_post_sync_external_projects()
endif()

if (COMMAND j_pre_sync_libraries)
	j_pre_sync_libraries()
endif()
j_sync_libraries()
if (COMMAND j_post_sync_libraries)
	j_post_sync_libraries()
endif()
j_show_list_libs()

j_load_scripts("${j_project_root}/build/cmake/*.cmake")

j_load_scripts("${j_project_root}/build/local/*.cmake")

# add CMakeLists.txt for each project
j_add_projects(${j_project_root}/${j_projects_dir} projects)
if (COMMAND j_post_add_projects)
	j_post_add_projects()
endif()

